<?php
class memberMod extends MY_Model{
	
	function __construct(){
		parent::__construct(
			'member',
			array(
				'id_member',
				'username',
				'password',
				'images_large',
				'images_medium',
				'images_small',
				'images_type',
				'type',
				'status',
				'posted'
			),
			'id_member'
		);
	}
	
	function generateID($data){
		return do_hash($data.(unix_to_human(time(),true,'eu')."MemberNewMod").$this->table_name);
	}
	
	function add($newData){
		$newData['posted'] = unix_to_human(time(),true,'eu');
		$newData['password'] = do_hash($newData['password'],md5);
		$this->db->insert($this->table_name, $newData);
	}
	
	function update($id,$newData){
		$newData['posted'] = unix_to_human(time(),true,'eu');
		$this->db->where($this->table_fields[0], $id);
		return $this->db->update($this->table_name, $newData);
	}
	
	function delete($ids){
		if (!is_array($ids)) $ids = array($ids);
    	foreach($ids as $pk) {
    		$this->db->or_where($this->table_fields[0], $pk);	
    	}
    	return $this->db->delete($this->table_name, $pk);
	}
	
	function remove($ids){
    	return $this->db->delete($this->table_name, array($this->table_fields[0]=>$ids));
    }
	
 	function get($id){
		return $this->db->get_where($this->table_name, array($this->table_fields[0]=>$id));
    }
    
	function get_record($limit=0,$offset=20){
		
		$this->db->limit($offset,$limit);
		$this->db->order_by('posted','desc');		
		return $this->db->get($this->table_name);
    }

	function get_where($where,$limit=0,$offset=20){
//    	return $this->db->get_where($this->table_name, $where, $limit, $offset);
		$this->db->like('username',$where,'both');
//		$this->db->or_like('description',$where,'both');
		$this->db->order_by('posted','desc');
		$this->db->limit($offset,$limit);
    	return $this->db->get($this->table_name);
    }
	
}